package com.itHsuSE.demo1;

import java.util.Arrays;
import java.util.Scanner;

public class HomeWork1 {
    public static void main(String[] args) {
        int[] arr=new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i]=(int)(Math.random()*100)+1;
        }
        System.out.println(Arrays.toString(arr));

        int max=arr[0];
        int maxIndex = 0;
        for (int i = 1; i < arr.length; i++) {
            if(max<arr[i]){
                max=arr[i];
                maxIndex=i;
            }
        }
        int min=arr[0];
        int minIndex=0;
        for (int i = 1; i < arr.length; i++) {
            if(min>arr[i]){
                min=arr[i];
                minIndex=i;
            }
        }
        double sum=0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        System.out.println(sum/arr.length+" "+max+" "+maxIndex+" "+min+" "+minIndex);
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]<arr[j+1]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    public static void main8(String[] args) {
        int[] arr = {10, 12, 45, 90};
        int[] newArr = new int[arr.length + 1];
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要插入数组的数字：");
        int num = sc.nextInt();
        int index = -1;
        for (int i = 0; i < arr.length; i++) {
            if (num <= arr[i]) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            index = arr.length;
        }
        for (int i = 0, j = 0; i < newArr.length; i++) {
            if (i != index) {
                newArr[i] = arr[j];
                j++;
            } else {
                newArr[i] = num;
            }
        }
        System.out.println(Arrays.toString(newArr));
    }

    public static void main7(String[] args) {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            for (int j = 1; j <= i; j++) {
                sum += j;
            }
        }
        System.out.println(sum);
    }

    public static void main6(String[] args) {
        double sum = 0;
        boolean flag = true;
        for (int i = 1; i <= 100; i++) {
            if (flag == true) {
                sum += 1.0 / i;
                flag = false;
            } else {
                sum -= 1.0 / i;
                flag = true;
            }
        }
        System.out.println(sum);
    }

    public static void main5(String[] args) {
        char num = 'a';
        for (int i = 0; i < 26; i++) {
            System.out.print(num);
            num++;
        }
        System.out.println();
        num = 'Z';
        for (int i = 0; i < 26; i++) {
            System.out.print(num);
            num--;
        }
    }

    public static void main4(String[] args) {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 5 != 0) {
                System.out.print(i + " ");
                count++;
            }
            if (count == 5) {
                count = 0;
                System.out.println();
            }
        }
    }

    public static void main3(String[] args) {
        for (int i = 100; i < 1000; i++) {
            int x = i % 10;
            int y = i / 10 % 10;
            int z = i / 100;
            if (x * x * x + y * y * y + z * z * z == i) {
                System.out.println(i);
            }
        }
    }

    public static void main2(String[] args) {
        double num = 100000;
        int count = 0;
        while (num > 1000) {
            if (num > 50000) {
                num -= num * 0.05;
                count++;
            } else {
                num -= 1000;
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main1(String[] args) {
        String str1 = "天龙八部";
        String str2 = "地龙八部";
        System.out.println(str1 + str2);//天龙八部地龙八部
        System.out.println("=======");
        char c1 = '男';
        char c2 = '女';
        System.out.println(c1 + c2);//输出‘男’和‘女’分别对应的字符码值相加
        System.out.println("=======");
        int n1 = 123;
        int n2 = 124;
        System.out.println(n1 + n2);//123+124=247
        int x = 4;
        x += 3.5;//(int)(x+3.5)
        System.out.println(x);//7
    }
}
